package com.yang.common.exception;


import com.yang.model.common.dtos.AppHttpCodeEnum;
import com.yang.model.common.dtos.ResultCode;

/**
 * @author: Billyang
 * @date: 2024/9/17 22:42
 */
public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private Integer code;
    private String message;

    public BusinessException(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public BusinessException(String message) {
        this.code = ResultCode.SYSTEM_ERROR.getCode();
        this.message = message;
    }

    public BusinessException(AppHttpCodeEnum appHttpCodeEnum){
        this.code = appHttpCodeEnum.getCode();
        this.message = appHttpCodeEnum.getErrorMessage();
    }

    public BusinessException(String message, Throwable e) {
        super(message, e);
        this.message = message;
    }

    public static BusinessException of(ResultCode resultCode) {
        return new BusinessException(resultCode.getCode(), resultCode.getMessage());
    }

    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
